package com.consumer2.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitmqConfig {

    public static final String QUEUE_TRANSFER_MOVIE = "queue_transfer_movie";
    public static final String EXCHANGE_TOPICS ="exchange_topics";
    public static final String ROUTINGKEY_SMS="transfer.movie.key";

    //声明topic交换机
    @Bean(EXCHANGE_TOPICS)
    public Exchange EXCHANGE_TOPICS() {
        //durable(true) 持久化，mq重启之后交换机还在
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS).durable(true).build();
    }

    //声明队列
    @Bean(QUEUE_TRANSFER_MOVIE)
    public Queue QUEUE_SMS(){
        return new Queue(QUEUE_TRANSFER_MOVIE);
    }

    //ROUTINGKEY_SMS队列绑定交换机，指定routingKey
    @Bean
    public Binding BINDING_ROUTINGKEY_SMS(@Qualifier(QUEUE_TRANSFER_MOVIE) Queue queue,
                                          @Qualifier(EXCHANGE_TOPICS) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
    }

}
